feat(grok): multi-agent visibility via task.* events - #5425
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review 1 blocking correctness issue found. This PR introduces significant new Grok functionality including multi-agent task visibility, plan mode handling, and token usage tracking across multiple files. The scope qualifies as a new feature requiring human review, and there are unresolved comments identifying potential bugs in context window handling and subagent event sequencing. You can customize Macroscope's approvability policy. Learn more. |
|
Review findings from Bugbot/Macroscope for this slice are fixed on the Zoen product tip ( |
Shared AcpRuntimeModel/CoreRuntimeEvents/SessionRuntime and xAI extension hooks used by the Grok adapter (and related fixtures).
Grok driver/adapter/provider core: slash catalog, process-scoped effort, usage meter, auth surface, set_model. Plan toggle and multi-agent task mapping land in later stack layers.
ecb811b to
3929597
Compare
| ingest(input.sessionModels?.availableModels); | ||
| const initializeModelState = input.initializeMeta?.modelState; | ||
| if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) { | ||
| const availableModels = initializeModelState.availableModels.flatMap((entry) => { | ||
| if (!isRecord(entry) || typeof entry.modelId !== "string") { | ||
| return [] as Array<{ modelId: string; _meta?: unknown }>; | ||
| } | ||
| return [{ modelId: entry.modelId, _meta: entry._meta }]; | ||
| }); | ||
| ingest(availableModels); | ||
| } |
There was a problem hiding this comment.
🟡 Medium Layers/GrokAdapter.ts:380
buildGrokModelContextWindows ingests session model state first, then unconditionally ingests initialize metadata into the same Map, so an initialize entry with the same modelId overwrites the authoritative session value. When the two context-window values differ, downstream code reads the stale initialize value and reports an incorrect context limit. Ingest initialize data first, or skip keys already set from session state.
| ingest(input.sessionModels?.availableModels); | |
| const initializeModelState = input.initializeMeta?.modelState; | |
| if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) { | |
| const availableModels = initializeModelState.availableModels.flatMap((entry) => { | |
| if (!isRecord(entry) || typeof entry.modelId !== "string") { | |
| return [] as Array<{ modelId: string; _meta?: unknown }>; | |
| } | |
| return [{ modelId: entry.modelId, _meta: entry._meta }]; | |
| }); | |
| ingest(availableModels); | |
| } | |
| ingest(input.sessionModels?.availableModels); | |
| const initializeModelState = input.initializeMeta?.modelState; | |
| if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) { | |
| const availableModels = initializeModelState.availableModels.flatMap((entry) => { | |
| if (!isRecord(entry) || typeof entry.modelId !== "string") { | |
| return [] as Array<{ modelId: string; _meta?: unknown }>; | |
| } | |
| return [{ modelId: entry.modelId, _meta: entry._meta }]; | |
| }); | |
| for (const model of availableModels) { | |
| const id = model.modelId.trim(); | |
| if (!id || windows.has(id)) continue; | |
| const tokens = totalContextTokensFromMeta(model._meta); | |
| if (tokens !== undefined) { | |
| windows.set(id, tokens); | |
| } | |
| } | |
| } |
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/provider/Layers/GrokAdapter.ts around lines 380-390:
`buildGrokModelContextWindows` ingests session model state first, then unconditionally ingests initialize metadata into the same `Map`, so an initialize entry with the same `modelId` overwrites the authoritative session value. When the two context-window values differ, downstream code reads the stale initialize value and reports an incorrect context limit. Ingest initialize data first, or skip keys already set from session state.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3929597. Configure here.
| payload: event.rawPayload, | ||
| }, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Completed-only subagent lacks start
Medium Severity
Live Grok often reports spawn_subagent only as completed, but this path emits task.completed without a preceding task.started. Projection titles completed tasks from the started description, so the computed title is unused and multi-agent rows show without a useful name—the common live case called out in the PR.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 3929597. Configure here.


What Changed
Map Grok in-process subagent tools (
spawn_subagentand relatives) to T3task.started/task.completedso multi-agent work is visible like Claude Task tools.Stacked on #5424. Fixes #5420
Why
Live
grok agent stdioemits tool_call titlespawn_subagentwith completed status and subagent_id (verified 2026-08-05). V1 deliberately ignored child sessions (#3156); product still needs parent-turn visibility of spawned work without flattening child transcripts.UI Changes
Uses existing task/work-log surfaces — no new components. Visibility of subagent rows in the thread timeline.
Checklist
Known review findings (must fix — real bugs)
Test plan
Model: grok-4.5 (Grok Build)
Note
Medium Risk
Large Grok adapter and provider snapshot changes affect runtime events and composer behavior; reviewers flagged possible task/tool eventId collisions and subagent detector false positives.
Overview
Grok
spawn_subagent(and similar) tool calls now emittask.started/task.completedon the parent turn so multi-agent work shows up in existing task/work-log UI, with per-toolCallIddedupe for started/completed.The diff is a broader Grok ACP alignment with live
grok agent stdio: ACP session updates for reasoning chunks, usage, available commands, config options, and session titles; token usage fromusage_updateand prompt result_meta;/compact→thread.state.changedcompacted; plan mode via/planprefix,exit_plan_modecapture, andplan.mdtool writes →turn.proposed.completed; mid-thread model/reasoning viasession/set_model_meta.reasoningEffortand CLI spawn flags (no forced new thread); slash/skills catalog pushed from initialize/available_commands_updatethroughGrokDriversnapshot streams; provider snapshot adds static/compact, reasoning effort options, and updated Grok presentation flags.The mock ACP agent and tests cover unsolicited JSON-RPC ids, init commands, compact, session info, usage meta, and the new adapter paths.
Reviewed by Cursor Bugbot for commit 3929597. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add multi-agent task visibility and reasoning effort support to the Grok provider via task.* events
task.startedandtask.completedruntime events for Grok subagent tool calls, surfacing multi-agent activity in the thread UI.--reasoning-effort, passes_meta.reasoningEffortthroughsession/set_model, and exposes a Reasoning select option in model capabilities when advertised by ACP.availableCommandsfrom ACP initialize result to populate slash commands and skills (including a static/compactcommand always present in the menu).thread.token-usage.updatedevents from both liveUsageUpdatedACP events and prompt RPC_meta, with granular input/output/cached/reasoning token breakdowns andmaxTokensfrom model context windows.x.ai/session_notificationwithauto_compact_completedto emitthread.state.changedwith compacted details, andsession_info_updateto emitthread.metadata.updatedwhen the session title changes./planprefix wheninteractionModeisplan, capturesplan.mdwrites andx.ai/exit_plan_modecalls to surface proposed-plan cards.requiresNewThreadForModelChangeis nowfalseandshowInteractionModeToggleis nowtruefor the Grok provider presentation.Macroscope summarized 3929597.